/*
The surface-physics project: http://code.google.com/p/surface-physics/
Adds real world physics based on the Bullet physics engine, to bases in the Orbiter space
flight simulation software.

Written by Abhijit Nandy
License : Apache License 2.0

Bump_Plate.h
BulletBase non-attachment, mesh based object management directly from within Bump
This class is a Component based object, specifically for modeling a plate of finite thickness

It requires adding animations and using Euler angles to transform the object properly


TODO : This class should read the options section of an object from the physics file

*/


#pragma once

#include "../Terrain/Bump_TerrainPatchOru.h"




/**
 * The Bump_Plate class to create and manage a plate
 */
class Bump_Plate : public Bump_BaseObject
{
	static Registrar registrar;

	static int count;


	//Physics stuff
	btRigidBody *rbPlate;
	btScalar mass;


	//Position in Bullet world
	btTransform transComponent;
	btVector3 originComponent;
	double x, y, z;
	btScalar rx, ry, rz;


	//Current position wrt base
	VECTOR3 rposCurrent, gposCurrent;
	double lng, lat, rad;


	//Animation stuff
	MGROUP_TRANSLATE *mgtTY, *mgtTZ; //mgtTX is static and declared in function(must be as its first)
	MGROUP_ROTATE *mgrRX, *mgrRY, *mgrRZ;
	UINT animTX, animTY, animTZ, animRX, animRY, animRZ;

	ANIMATIONCOMPONENT_HANDLE parent;
	UINT mshIndex;
	static const int GROUP_INDEX = 0;

	//Supporting terrain
	Bump_TerrainPatch *ground;


public:
	static Bump_BaseObject * create() { return new Bump_Plate; }

	Bump_Plate();
	virtual ~Bump_Plate();

	//Main control functions which are overidden from parent as they are called from Bump_BulletBase
	int		init(Bump_BulletBase *bb, char *strObjName,  OBJHANDLE hObj = NULL);
	int		poststep(double SimT, double SimDT, double MJD);
	int		reset();

	//Utility stuff
	int		createOrbiterPrimitives();
	int 	destroyOrbiterPrimitives();

	int		createBulletRigidBody();
	int		destroyBulletRigidBody();

	int		processCommand();


};
